package org.seed.quantum.socket;

public interface MessageProcessor<T> {


    /**
     * 处理接收到的消息
     *
     * @param session 通信会话
     * @param msg     待处理的业务消息
     */
    void process(AbstractSocketSession session, T msg);

    /**
     * 状态机事件,当枚举事件发生时由框架触发该方法
     *
     * @param session          本次触发状态机的AioSession对象
     * @param stateMachineEnum 状态枚举
     * @param throwable        异常对象，如果存在的话
     * @see SocketStateEnum
     */
    default void stateEvent(AbstractSocketSession session, SocketStateEnum stateMachineEnum, Throwable throwable) {
        if (stateMachineEnum == SocketStateEnum.DECODE_EXCEPTION || stateMachineEnum == SocketStateEnum.PROCESS_EXCEPTION) {
            throwable.printStackTrace();
        }
    }
}
